package com.horsecoder.im.common.protocol.action.handler;

import com.horsecoder.im.common.protocol.action.ActionHandlerEnum;
import com.horsecoder.im.common.protocol.context.chain.request.Request;
import com.horsecoder.im.common.protocol.context.chain.response.Response;
import io.netty.channel.Channel;

/**
 * Author: Zhu yuhan
 * Email: zhuyuhan2333@qq.com
 * Date: 2022/3/16 1:23 下午
 **/
public class ActionDispatcherHandler implements Handler {

    @Override
    public void handle(Channel channel, Request request, Response response) {
        Class<? extends Handler> actionHandler = ActionHandlerEnum.getActionHandler(request.getType());
        try {
            actionHandler.getDeclaredConstructor().newInstance().handle(channel, request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
